export module MyClass {
    export class Square {
        constructor(public width: number) { }
    }
    export class Rectangle extends Square {
        constructor(public width: number, public height: number) {
            super(width);
        }
    }
    export type Shape = Square | Rectangle;
    export function calculateArea(shape: Shape) {
        if (shape instanceof Rectangle) {
            shape;  // Type is Rectangle
            return shape.width * shape.height;
        } else {
            shape;  // Type is Square
            return shape.width * shape.width;  // OK
        }
    }
}